<?php
require('lib/verify.php');
require('lib/has_char.php');
require('lib/is_approved.php');

$system_id = $system["system_id"];
$sraid_id = $_GET["id"];

$sql = "select *, wm_instances.* from wm_scheduled_raids left join wm_instances on wm_instances.instance_id = scheduled_raid_instance where scheduled_raid_id = $sraid_id and scheduled_raid_system_id = $system_id";
$result = $db->query($sql);
$sraid = $db->fetch_assoc($result);

if($db->num_rows($result)<1) {
 header("Location: error-wrong-system.php");
 exit;
}


$_category = "warmath";
$_title = "Scheduled Raid / " . $sraid["instance_name"] . ", " . date("D d M Y g:i a", strtotime($sraid["scheduled_raid_datetime"]));
require('lib/head.php');

if($_GET["error"]!="") {
  boxRed("Error");
?>
    <?=$_GET["error"]?>
<?php
    boxBot();
    }

boxTop("Warmath: $_title");

?>
<a href="loot-instance.php?id=<?=$sraid["instance_id"]?>"><?=$sraid["instance_name"] ?></a>, <b><?=date("D d M Y g:i a", strtotime($sraid["scheduled_raid_datetime"]))?></b><br />
<i>Bosses:</i> 
<?php
$sql = "select *, wm_bosses.* from wm_scheduled_raid_bosses left join wm_bosses on wm_bosses.boss_id = wm_scheduled_raid_bosses.scheduled_raid_boss where scheduled_raid = '" . $sraid["scheduled_raid_id"] . "'";
$rez = $db->query($sql);
while($abo = $db->fetch_assoc($rez)) {
?>
<a href="boss.php?id=<?=$abo["boss_id"]?>"><?=$abo["boss_name"]?></a> 
<?php
}
?><?php if($sraid["scheduled_raid_comments"]!="") { ?><br />
							 <i><?=$sraid["scheduled_raid_comments"]?></i><? } ?>
<br />
<br />

<?php
$chara = $character["character_id"];
$raid_id = $sraid_id;

$sql = "select * from wm_scheduled_signups where scheduled_signup_raid = $raid_id and scheduled_signup_character = $chara";
$ress = $db->query($sql);

if($db->num_rows($ress)>0) {
?>
You're signed up for this raid.  <a href="un-signup.php?id=<?=$sraid["scheduled_raid_id"]?>">Can't make it?  Cancel your signup.</a>
<?php
}
else {
  if(strtotime($sraid["scheduled_raid_datetime"])>(time()+2*60*60)) {
?>
<b><a href="do-signup.php?id=<?=$sraid["scheduled_raid_id"]?>">Sign up for this raid</a></b>
<?php
										  }

  else {
?>
 Signups are closed (they automatically close 2 hours before a raid starts).
<?php
  }
}

?>

<br /><br />
<b>Signed up</b><?php
   if($character["character_admin"]) {
     ?>
<form action="add-signupee.php" method="post">
     (<?adminfeature()?> 
<input type="hidden" name="rid" value="<?=$sraid["scheduled_raid_id"]?>">
<select name="id">
<?php
      $rid = $sraid["scheduled_raid_id"];
      $sql = "select * from wm_characters where character_id not in (select scheduled_signup_character from wm_scheduled_signups where scheduled_signup_raid=$rid) and character_system_id=$system_id and character_approved = 1 order by character_name asc";
      echo $sql;
      $result = $db->query($sql);
      while($acha = $db->fetch_assoc($result)) {
?>
<option value="<?=$acha["character_id"]?>"><?=$acha["character_name"]?></option>
<?php
      }
?>

</select>
<input type="submit" value="Add">)
</form>
<?php
   }
?><br />
<?php
$sql = "select * , wm_characters.* from wm_scheduled_signups left join wm_characters on wm_characters.character_id = wm_scheduled_signups.scheduled_signup_character where scheduled_signup_system_id = $system_id and scheduled_signup_raid = $sraid_id group by character_id order by character_class asc, character_dkp_satout desc, character_name asc";
$result = $db->query($sql);
?>
<i><?=$db->num_rows($result)?> characters</i><br/>
<?php
while($attendee = $db->fetch_assoc($result)) {
?>
<?cclass($attendee["character_class"])?> <a href="character.php?id=<?=$attendee["character_id"]?>"><?=$attendee["character_name"]?></a>
(<?=round($attendee["character_dkp_satout"],2)?> satout dkp)
<i><?=$attendee["scheduled_signup_comments"]?></i><?php
   if($character["character_admin"]) {
?>
     (<?adminfeature()?> <a href="remove-signupee.php?id=<?=$attendee["character_id"]?>&rid=<?=$sraid_id?>">remove</a>)
<?php
   }
?><br />
<?php
    }
?>
<br/>
<b>Overall Role Breakdown and Desired Bosses</b><br />
<table>
<tr>
<th>Potential Tanks</th>
<th>Potential Healers</th>
<th>Pure DPS</th>
</tr>
<tr>
<td valign="top">
<?php
$sql = "select * , wm_characters.* from wm_scheduled_signups left join wm_characters on wm_characters.character_id = wm_scheduled_signups.scheduled_signup_character where (character_class = 'Druid' or character_class='Warrior') and scheduled_signup_system_id = $system_id and scheduled_signup_raid = $sraid_id group by character_id order by character_dkp_satout desc, character_class asc, character_name asc";
$result = $db->query($sql);
?>
<i><?=$db->num_rows($result)?> characters</i><br/>
<?php
while($attendee = $db->fetch_assoc($result)) {
?>
<?cclass($attendee["character_class"])?> <a href="character.php?id=<?=$attendee["character_id"]?>"><?=$attendee["character_name"]?></a>
(<?=round($attendee["character_dkp_satout"],2)?> satout dkp)
<?php
$cchar = $attendee["character_id"];
$iinst = $sraid["scheduled_raid_instance"];
$srai = $sraid["scheduled_raid_id"];
$sql = "SELECT wm_bosses.* FROM `wm_wishes` left join wm_items on wm_wishes.wish_item = wm_items.item_id left join wm_bosses on wm_items.item_boss = wm_bosses.boss_id left join wm_scheduled_raid_bosses on wm_scheduled_raid_bosses.scheduled_raid_boss = wm_bosses.boss_id WHERE wm_scheduled_raid_bosses.scheduled_raid = $srai and wish_character=$cchar and boss_instance = $iinst and boss_trash = 0 group by boss_id";
$rez = $db->query($sql);
if($db->num_rows($rez) > 0) {
?>
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<?php
}
while($aboss = $db->fetch_assoc($rez)) {
?>
<a title="<?=$aboss["boss_name"]?>" href="boss.php?id=<?=$aboss["boss_id"]?>"><?=$aboss["boss_name_short"]?></a> 
<?php
}
?>
<br />
<?php
    }
?>

</td>
<td valign="top">
<?php
$sql = "select * , wm_characters.* from wm_scheduled_signups left join wm_characters on wm_characters.character_id = wm_scheduled_signups.scheduled_signup_character where (character_class = 'Druid' or character_class='Priest' or character_class='Shaman' or character_class='Paladin') and scheduled_signup_system_id = $system_id and scheduled_signup_raid = $sraid_id group by character_id order by character_dkp_satout desc, character_class asc, character_name asc";
$result = $db->query($sql);
?>
<i><?=$db->num_rows($result)?> characters</i><br/>
<?php
while($attendee = $db->fetch_assoc($result)) {
?>
<?cclass($attendee["character_class"])?> <a href="character.php?id=<?=$attendee["character_id"]?>"><?=$attendee["character_name"]?></a>
(<?=round($attendee["character_dkp_satout"],2)?> satout dkp)
<?php
$cchar = $attendee["character_id"];
$iinst = $sraid["scheduled_raid_instance"];
$srai = $sraid["scheduled_raid_id"];
$sql = "SELECT wm_bosses.* FROM `wm_wishes` left join wm_items on wm_wishes.wish_item = wm_items.item_id left join wm_bosses on wm_items.item_boss = wm_bosses.boss_id left join wm_scheduled_raid_bosses on wm_scheduled_raid_bosses.scheduled_raid_boss = wm_bosses.boss_id WHERE wm_scheduled_raid_bosses.scheduled_raid = $srai and wish_character=$cchar and boss_instance = $iinst and boss_trash = 0 group by boss_id";
$rez = $db->query($sql);
if($db->num_rows($rez) > 0) {
?>
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<?php
}
while($aboss = $db->fetch_assoc($rez)) {
?>
<a title="<?=$aboss["boss_name"]?>" href="boss.php?id=<?=$aboss["boss_id"]?>"><?=$aboss["boss_name_short"]?></a> 
<?php
}
?>
<br />
<?php
    }
?>

</td>
<td valign="top">
<?php
$sql = "select * , wm_characters.* from wm_scheduled_signups left join wm_characters on wm_characters.character_id = wm_scheduled_signups.scheduled_signup_character where (character_class = 'Mage' or character_class='Warlock' or character_class='Rogue' or character_class='Hunter') and scheduled_signup_system_id = $system_id and scheduled_signup_raid = $sraid_id group by character_id order by character_dkp_satout desc, character_class asc, character_name asc";
$result = $db->query($sql);
?>
<i><?=$db->num_rows($result)?> characters</i><br/>
<?php
while($attendee = $db->fetch_assoc($result)) {
?>
<?cclass($attendee["character_class"])?> <a href="character.php?id=<?=$attendee["character_id"]?>"><?=$attendee["character_name"]?></a>
(<?=round($attendee["character_dkp_satout"],2)?> satout dkp)
<?php
$cchar = $attendee["character_id"];
$iinst = $sraid["scheduled_raid_instance"];
$srai = $sraid["scheduled_raid_id"];
$sql = "SELECT wm_bosses.* FROM `wm_wishes` left join wm_items on wm_wishes.wish_item = wm_items.item_id left join wm_bosses on wm_items.item_boss = wm_bosses.boss_id left join wm_scheduled_raid_bosses on wm_scheduled_raid_bosses.scheduled_raid_boss = wm_bosses.boss_id WHERE wm_scheduled_raid_bosses.scheduled_raid = $srai and wish_character=$cchar and boss_instance = $iinst and boss_trash = 0 group by boss_id";
$rez = $db->query($sql);
if($db->num_rows($rez) > 0) {
?>
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<?php
}
while($aboss = $db->fetch_assoc($rez)) {
?>
<a title="<?=$aboss["boss_name"]?>" href="boss.php?id=<?=$aboss["boss_id"]?>"><?=$aboss["boss_name_short"]?></a> 
<?php
}
?>
<br />
<?php
    }
?>
</td>
</tr>
</table>
<br />


<?php

$sql = "select *, wm_bosses.* from wm_scheduled_raid_bosses left join wm_bosses on wm_bosses.boss_id = wm_scheduled_raid_bosses.scheduled_raid_boss where scheduled_raid = '" . $sraid["scheduled_raid_id"] . "'";
$rezz = $db->query($sql);
while($abo = $db->fetch_assoc($rezz)) {
?>
<b><a href="boss.php?id=<?=$abo["boss_id"]?>"><?=$abo["boss_name"]?></a></b><br />
<i>Characters are listed by satout dkp; those with wishes for items from the boss are listed <b>in bold</b>.</i><br />

<table>
<tr>
<th>Potential Tanks</th>
<th>Potential Healers</th>
<th>Pure DPS</th>
</tr>
<tr>
<td valign="top">
<?php
$sql = "select * , wm_characters.* from wm_scheduled_signups left join wm_characters on wm_characters.character_id = wm_scheduled_signups.scheduled_signup_character where (character_class = 'Druid' or character_class='Warrior') and scheduled_signup_system_id = $system_id and scheduled_signup_raid = $sraid_id group by character_id order by character_dkp_satout desc, character_class asc, character_name asc";
$result = $db->query($sql);
?>
<i><?=$db->num_rows($result)?> characters</i><br/>
<?php
$att = array();

$ww = array();
$nw = array();

//first, people who have wishes on this boss (sorted by satout)
//then people who don't have wishes on this boss (sorted by satout)
 $wa = array();

while($attendee = $db->fetch_assoc($result)) {
$att[$attendee["character_id"]] = $attendee;
 $sql = "select * from wm_wishes left join wm_items on wm_items.item_id = wm_wishes.wish_item where wish_character = '" . $attendee["character_id"] . "' and item_boss = " . $abo["boss_id"];
 $resss = $db->query($sql);
 $nr = $db->num_rows($resss);
 if($nr > 0) {
   $ww[$attendee["character_id"]] = $attendee;
   $att[$attendee["character_id"]]["with_wish"] = 1;
   $i = 0;
   while($it = $db->fetch_assoc($resss)) {
     $wa[$attendee["character_id"]][$i] = $it;
     $i++;
       }
 }
 else {
   $nw[$attendee["character_id"]] = $attendee;
 }
?>
<?php
}
while(list($id, $attendee) = each($att)) {
?>
 <?cclass($attendee["character_class"])?> <?php
 if($att[$id]["with_wish"]==1) { 
?><b><? } ?><a href="character.php?id=<?=$attendee["character_id"]?>"><?=$attendee["character_name"]?></a>
<? if($att[$id]["with_wish"]==1) { ?>
</b>
<? } ?>
(<?=round($attendee["character_dkp_satout"],2)?> satout dkp)
<br />
<? if($att[$id]["with_wish"]==1) { ?>
 <? while(list($kk, $vv) = each($wa[$id])) { ?>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?show_link($vv)?>
<? } } ?>

<?php
    }
																											   /*
while(list($id, $attendee) = each($nw)) {
?>
<?cclass($attendee["character_class"])?> <a href="character.php?id=<?=$attendee["character_id"]?>"><?=$attendee["character_name"]?></a>
(<?=round($attendee["character_dkp_satout"],2)?> satout dkp)
<br />
<?php
    }*/
?>

</td>
<td valign="top">
<?php
$sql = "select * , wm_characters.* from wm_scheduled_signups left join wm_characters on wm_characters.character_id = wm_scheduled_signups.scheduled_signup_character where (character_class = 'Druid' or character_class='Priest' or character_class='Shaman' or character_class='Paladin') and scheduled_signup_system_id = $system_id and scheduled_signup_raid = $sraid_id group by character_id order by character_dkp_satout desc, character_class asc, character_name asc";
$result = $db->query($sql);
?>
<i><?=$db->num_rows($result)?> characters</i><br/>
<?php
$att = array();

$ww = array();
$nw = array();

//first, people who have wishes on this boss (sorted by satout)
//then people who don't have wishes on this boss (sorted by satout)
 $wa = array();

while($attendee = $db->fetch_assoc($result)) {
$att[$attendee["character_id"]] = $attendee;
 $sql = "select * from wm_wishes left join wm_items on wm_items.item_id = wm_wishes.wish_item where wish_character = '" . $attendee["character_id"] . "' and item_boss = " . $abo["boss_id"];
 $resss = $db->query($sql);
 $nr = $db->num_rows($resss);
 if($nr > 0) {
   $ww[$attendee["character_id"]] = $attendee;
   $att[$attendee["character_id"]]["with_wish"] = 1;
   $i = 0;
   while($it = $db->fetch_assoc($resss)) {
     $wa[$attendee["character_id"]][$i] = $it;
     $i++;
       }
 }
 else {
   $nw[$attendee["character_id"]] = $attendee;
 }
?>
<?php
}
while(list($id, $attendee) = each($att)) {
?>
 <?cclass($attendee["character_class"])?> <?php
 if($att[$id]["with_wish"]==1) { 
?><b><? } ?><a href="character.php?id=<?=$attendee["character_id"]?>"><?=$attendee["character_name"]?></a>
<? if($att[$id]["with_wish"]==1) { ?>
</b>
<? } ?>
(<?=round($attendee["character_dkp_satout"],2)?> satout dkp)
<br />
<? if($att[$id]["with_wish"]==1) { ?>
 <? while(list($kk, $vv) = each($wa[$id])) { ?>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?show_link($vv)?>
<? } } ?>
<?php    }
																											   /*
while(list($id, $attendee) = each($nw)) {
?>
<?cclass($attendee["character_class"])?> <a href="character.php?id=<?=$attendee["character_id"]?>"><?=$attendee["character_name"]?></a>
(<?=round($attendee["character_dkp_satout"],2)?> satout dkp)
<br />
<?php
    }*/
?>



</td>
<td valign="top">


<?php
$sql = "select * , wm_characters.* from wm_scheduled_signups left join wm_characters on wm_characters.character_id = wm_scheduled_signups.scheduled_signup_character where (character_class = 'Mage' or character_class='Warlock' or character_class='Rogue' or character_class='Hunter') and scheduled_signup_system_id = $system_id and scheduled_signup_raid = $sraid_id group by character_id order by character_dkp_satout desc, character_class asc, character_name asc";
$result = $db->query($sql);
?>
<i><?=$db->num_rows($result)?> characters</i><br/>
<?php
$att = array();

$ww = array();
$nw = array();

//first, people who have wishes on this boss (sorted by satout)
//then people who don't have wishes on this boss (sorted by satout)
 $wa = array();

while($attendee = $db->fetch_assoc($result)) {
$att[$attendee["character_id"]] = $attendee;
 $sql = "select * from wm_wishes left join wm_items on wm_items.item_id = wm_wishes.wish_item where wish_character = '" . $attendee["character_id"] . "' and item_boss = " . $abo["boss_id"];
 $resss = $db->query($sql);
 $nr = $db->num_rows($resss);
 if($nr > 0) {
   $ww[$attendee["character_id"]] = $attendee;
   $att[$attendee["character_id"]]["with_wish"] = 1;
   $i = 0;
   while($it = $db->fetch_assoc($resss)) {
     $wa[$attendee["character_id"]][$i] = $it;
     $i++;
       }
 }
 else {
   $nw[$attendee["character_id"]] = $attendee;
 }
?>
<?php
}
while(list($id, $attendee) = each($att)) {
?>
 <?cclass($attendee["character_class"])?> <?php
 if($att[$id]["with_wish"]==1) { 
?><b><? } ?><a href="character.php?id=<?=$attendee["character_id"]?>"><?=$attendee["character_name"]?></a>
<? if($att[$id]["with_wish"]==1) { ?>
</b>
<? } ?>
(<?=round($attendee["character_dkp_satout"],2)?> satout dkp)
<br />
<? if($att[$id]["with_wish"]==1) { ?>
 <? while(list($kk, $vv) = each($wa[$id])) { ?>
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?show_link($vv)?>
<? } } ?>
<?php
    }
																											   /*
while(list($id, $attendee) = each($nw)) {
?>
<?cclass($attendee["character_class"])?> <a href="character.php?id=<?=$attendee["character_id"]?>"><?=$attendee["character_name"]?></a>
(<?=round($attendee["character_dkp_satout"],2)?> satout dkp)
<br />
<?php
    }*/
?>


</td>
</tr>
</table><br />


<?php
    }

boxBot();
?>

<?php
require('lib/foot.php');
?>

